﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CreditCard
{
    public partial class Home : Form
    {
        public Home()
        {
            InitializeComponent();
        }

        public Home(AppHome app)
        {
            InitializeComponent();
            this.app = app;
        }

        MySqlDao mySqlDao = new MySqlDao();

        AppHome app;

        //登录
        private void loginButton_Click(object sender, EventArgs e)
        {
            if (id.Text == "" || pass.Text == "")
            {
                warn_label.Text = "请输入账号和密码...";
                return;
            }
            else
            {
                if (u.Checked)
                {
                    User user = mySqlDao.userLogin(id.Text, pass.Text);
                    if (user.U_id!="")
                    {
                        app.openForm(new UserHome(app, user));
                    }
                    else
                    {
                        warn_label.Text = "账号或密码错误...";
                    }
                }
                else
                {
                   
                    Admin admin = mySqlDao.adminLogin(id.Text, pass.Text);
                    if (admin.A_id!="")
                    {
                        app.openForm(new AdminHome(app, admin));
                    }
                    else
                    {
                        warn_label.Text = "账号或密码错误...";
                    }
                }
            }
        }

        private void registerButton_Click(object sender, EventArgs e)
        {
            app.openForm(new Register(app));
        }

        private void change(object sender, EventArgs e)
        {
            warn_label.Text = "";
        }
    }
}
